﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          liuleyi
        更新时间：      20150530
        用途：          生成存储过程默认模板
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:variable name="MetadataTypeDefine" select="document('../model/0101_metadataTypeDefine.xml')"/>
	<xsl:result-document encoding="utf-8" method="text" href="./generate/sql/proc/proc_td.sql"><xsl:for-each select="Functions/Function">
CREATE PROCEDURE P<xsl:value-of select="@func_no"/>(po_Cursor  OUT Pkg_Type.Cursor_Type,
                           Pi_fix Typ_Fix_Para,<xsl:for-each select="Request"><xsl:for-each select="Field">
			   <xsl:variable name="typeTable" select="@name"/>
                           pi_<xsl:value-of select="@name"/>  pkg_type.<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if><xsl:for-each select="$MetadataTypeDefine//Enum[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//String[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Money[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Price[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Ratio[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Long[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Int[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Boolean[@typename=$typeTable]">--<xsl:value-of select="@label "/></xsl:for-each>
</xsl:for-each>
</xsl:for-each>
                                                    ) is
/*
  名称:P<xsl:value-of select="@func_no"/>
  功能描述:<xsl:value-of select="@func_name"/>
-----------------------------------------------------------
  修改记录
    版本号   |编辑时间          |编辑人       |修改描述
    1         |<xsl:value-of select="current-dateTime()"/>|自动化脚本   |创建此程式

-----------------------------------------------------------
  参数描述:
  请求参数:
<xsl:for-each select="Request"><xsl:for-each select="Field">
<xsl:variable name="typeTable" select="@name"/>
|<xsl:value-of select="@name"/>       |<xsl:for-each select="$MetadataTypeDefine//Enum[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//String[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Money[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Price[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Ratio[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Long[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Int[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Boolean[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>|</xsl:for-each>
</xsl:for-each>
  响应参数:
<xsl:for-each select="Response"><xsl:for-each select="Field">
<xsl:variable name="typeTable" select="@name"/>
|<xsl:value-of select="@name"/>       |<xsl:for-each select="$MetadataTypeDefine//Enum[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//String[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Money[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Price[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Ratio[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Long[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Int[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>
<xsl:for-each select="$MetadataTypeDefine//Boolean[@typename=$typeTable]">--<xsl:value-of select="@label "/>
</xsl:for-each>|</xsl:for-each>
</xsl:for-each>
-----------------------------------------------------------
*/
  --固定变量声明区域--START
  v_Errorcode Pkg_Type.Errorcode;
  v_Errormsg  Pkg_Type.Errormsg;
  v_Expcetion EXCEPTION;
  v_Updatedate      Pkg_Type.Updatedate;
  v_Updatetime      Pkg_Type.Updatetime;
  v_Rowcnt          Pkg_Type.Rowcnt;
  --固定变量声明区域--END
  --
BEGIN
  --固定变量初始化--START
  v_Errorcode := 0;
  v_Errormsg := '';
  v_Updatedate      := Pkg_Tool.Getoperdate;
  v_Updatetime      := Pkg_Tool.Getopertime;
  v_Rowcnt          := 0;
  --固定变量初始化--END
  --固定入参非空检查--START
  <xsl:for-each select="Request">
  <xsl:for-each select="Field">
      <xsl:if test="@isRequired='true'">
      IF pi_<xsl:value-of select="@name"/> IS NULL THEN
         v_Errormsg := v_Errormsg||'['||pkg_type.LB_<xsl:value-of select="@name"/>||']';
      END IF;
      </xsl:if>
  </xsl:for-each>
  </xsl:for-each>
      IF v_Errormsg IS NOT NULL THEN
        v_Errorcode := -20999;
        v_Errormsg := v_Errormsg||'不能为空';
        RAISE v_Expcetion;
      END IF;
  --固定入参非空检查--END
EXCEPTION
  --固定异常捕捉--START
  WHEN v_Expcetion THEN
    ROLLBACK;
    p_Lg_Raise_Error(Pi_Fix     => Pi_Fix,
                     Pi_Code    => v_Errorcode,
                     Pi_Msg     => v_Errormsg,
                     Pi_Dbobjid => Pkg_Tool.Getobjid);
  
  WHEN OTHERS THEN
    ROLLBACK;
    v_Errorcode := SQLCODE;
    v_Errormsg  := SQLERRM;
    p_Lg_Raise_Error(Pi_Fix     => Pi_Fix,
                     Pi_Code    => v_Errorcode,
                     Pi_Msg     => v_Errormsg,
                     Pi_Dbobjid => Pkg_Tool.Getobjid);
    RAISE;
  --固定异常捕捉--END
END;
/</xsl:for-each></xsl:result-document></xsl:template>  
</xsl:stylesheet>